﻿package net.wangit.adm.admin;

import net.wangit.adm.org.OrgTreeFactory;
import net.wangit.user.admin.Admin;
import net.wangit.user.admin.AdminFactory;
import net.wangit.util.Checker;
import net.wangit.view.tree.Tree;

public class AdminOrgTreeFactory extends OrgTreeFactory {

	private Admin administrator;

	public AdminOrgTreeFactory() {
	}

	public Tree createTree(String treeDoamin) throws Exception {
		String aid = AdminAuthUI.getAndSetAdministratorId();
		if (Checker.isEmpty(aid)) {
			return null;
		} else {
			administrator = AdminFactory.getAdmin(aid);
			return super.createTree(treeDoamin);
		}
	}

	protected void setCustomAttribute(Tree tree, String organizationId) {
		tree.setCheckValue(organizationId);
		if (administrator.containsOrganization(organizationId))
			tree.setCheckAttribute("checked");
	}

	protected void setName(Tree tree, String orgId, String orgName,
			int roleCount, int privilegeCount) {
		tree.setName((new StringBuilder(String.valueOf(roleCount))).append(" ")
				.append(orgName).append(privilegeCount).toString());
	}
}
